package o;

import android.content.Context;
import android.content.Intent;
import android.os.RemoteException;
import android.text.TextUtils;
import com.huawei.appmarket.service.externalservice.distribution.download.IDownloadCallback;
import com.huawei.appmarket.service.webview.base.jssdk.control.FullAppStatus;
import com.huawei.hms.support.hianalytics.HiAnalyticsConstant;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;

public class dzd implements end {
    private static final Object ˊ = new Object();
    private static dzd ˋ;
    private static final Object ˏ = new Object();
    private Context ˎ;
    private final Map<String, Map<String, IDownloadCallback>> ॱ = new ConcurrentHashMap();

    private dzd(Context context) {
        this.ˎ = context;
    }

    public static dzd ॱ(Context context) {
        dzd o_dzd;
        synchronized (ˊ) {
            if (ˋ == null) {
                ˋ = new dzd(context);
            }
            o_dzd = ˋ;
        }
        return o_dzd;
    }

    public void ˏ(String str, String str2, IDownloadCallback iDownloadCallback) {
        if (TextUtils.isEmpty(str)) {
            Logger.e("DownloadProgressRefreshManager", "can not register empty mediaPkg");
            return;
        }
        Map map = (Map) this.ॱ.get(str);
        synchronized (ˏ) {
            if (map == null) {
                map = new HashMap();
            }
            if (TextUtils.isEmpty(str2)) {
                str2 = "#####";
            }
            try {
                map.put(iDownloadCallback.getDownloadRegisterKey() + HiAnalyticsConstant.REPORT_VAL_SEPARATOR + str2, iDownloadCallback);
            } catch (RemoteException e) {
                return;
            }
        }
        this.ॱ.put(str, map);
        ˎ();
    }

    public void ˊ(String str, String str2, IDownloadCallback iDownloadCallback) {
        if (TextUtils.isEmpty(str)) {
            Logger.e("DownloadProgressRefreshManager", "can not unregister empty mediaPkg");
            return;
        }
        try {
            String downloadRegisterKey = iDownloadCallback.getDownloadRegisterKey();
            if (TextUtils.isEmpty(str2)) {
                str2 = "#####";
            }
            String str3 = downloadRegisterKey + HiAnalyticsConstant.REPORT_VAL_SEPARATOR + str2;
            Map map = (Map) this.ॱ.get(str);
            if (map != null) {
                synchronized (ˏ) {
                    map.remove(str3);
                }
                if (map.isEmpty()) {
                    this.ॱ.remove(str);
                }
            }
        } catch (RemoteException e) {
        }
    }

    public void ˎ() {
        enf.ˋ().ˎ("DownloadProgressRefreshManager", this);
        dxi.ˏ();
    }

    public void ॱ(FullAppStatus fullAppStatus) {
        if (!TextUtils.isEmpty(fullAppStatus.mediaPkg_)) {
            if (fullAppStatus.mediaPkg_.equals(fullAppStatus.callerPkg_)) {
                try {
                    if ((Integer.parseInt(fullAppStatus.extendDownloadFlags_) & 1) != 0) {
                        ˊ(fullAppStatus);
                    }
                } catch (NumberFormatException e) {
                    Logger.e("DownloadProgressRefreshManager", "can not get downloadFlags NumberFormatException");
                }
            } else if (dhd.ˏ().contains(fullAppStatus.callerPkg_)) {
                ˊ(fullAppStatus);
            }
            Map map = (Map) this.ॱ.get(fullAppStatus.mediaPkg_);
            if (map != null) {
                synchronized (ˏ) {
                    for (Entry entry : map.entrySet()) {
                        String str = (String) entry.getKey();
                        if (!TextUtils.isEmpty(str)) {
                            String[] split = str.split("\\|");
                            if (split.length == 2) {
                                str = split[1];
                                if (str.equals("#####") || str.equals(fullAppStatus.ˎ())) {
                                    try {
                                        ((IDownloadCallback) entry.getValue()).refreshAppStatus(fullAppStatus.ˎ(), fullAppStatus.appType_, fullAppStatus.ˋ(), fullAppStatus.ˊ());
                                    } catch (RemoteException e2) {
                                        Logger.e("DownloadProgressRefreshManager", "refreshAppStatus failed:RemoteException");
                                    }
                                }
                            } else {
                                continue;
                            }
                        }
                    }
                }
            }
        }
    }

    private void ˊ(FullAppStatus fullAppStatus) {
        Intent intent = new Intent("com.huawei.appmarket.broadcast.action.APP_STATUS");
        intent.setPackage(fullAppStatus.callerPkg_);
        intent.putExtra("task.pkg", fullAppStatus.ˎ());
        intent.putExtra("task.mediaPkg", fullAppStatus.mediaPkg_);
        intent.putExtra("task.appType", fullAppStatus.appType_);
        intent.putExtra("task.appStatus", fullAppStatus.ˋ());
        intent.putExtra("task.progress", fullAppStatus.ˊ());
        intent.putExtra("task.contentId", fullAppStatus.contentId_);
        this.ˎ.sendBroadcast(intent);
    }
}
